package btanalyzer.db.report;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Component;

@Component("ReportSeeds")
public class ReportSeeds extends AbstractReport {
	
	@Override
	protected String reportOutptFileName() {
		return "ReportSeeds.txt";
	}
	
	@Override
	protected void generateInt() {
		Query q = em.createNativeQuery(
				"select t.seeds from torrent t where t.metadata_id is not null " +
				"order by t.seeds asc");
		@SuppressWarnings("unchecked")
		List<Integer> res = q.getResultList();
		int[] results = new int[1 + res.get(res.size() - 1)];
		for (int i = 0; i < results.length; i++) {
			results[i] = 0;
		}
		for (int i : res) {
			results[i]++;
		}
		
		// print results
		
		pw.println("Wszystkich wyników:\t" + res.size());
		pw.println();
		pw.println("ilosc seedow\tilosc torrentow");
		for (int i = 0; i < results.length; i++) {
			long l = results[i];
			pw.println(i + "\t" + l);
		}
	}

}
